<?php
    /*
     * Destination
     */
    $dest_hot = lang('search.search_placeholder');

    if (isset($_GET['dest_hot']) && ($_GET['dest_hot'] != -1 ) && ($_GET['dest_hot'] != "" ))
        $dest_hot = $_GET['dest_hot'];

    /*
     * Checkin, Checkout
     */
    $check_in = date('d.m.Y', strtotime("+1 day"));

    if (isset($_GET['check_in']))
        $check_in = $_GET['check_in'];

    $check_out = date('d.m.Y', strtotime("+2 day"));

    if (isset($_GET['check_out']))
        $check_out = $_GET['check_out'];

//    $this->firephp->log($check_in);
//    $this->firephp->log($check_out);

    /*
     * Number persons
     */
    $sel_text = 'selected = "selected"';

    if (isset($_GET['nr_adults'])) {
        $selected = $_GET['nr_adults'];
        $cnt = 5;
    } else {
        $selected = 2;
        $cnt = 5;
    }

    if (isset($_GET['nr_childrens'])) {
        $selected_CH = $_GET['nr_childrens'];
        $cnt_CH = 5;
    } else {
        $selected_CH = 0;
        $cnt_CH = 5;
    }
?>
<form action="<?= base_url('search') ?>" method="get" class="show_search_form">

    <!-- TODO add two hidden inputs to pass currency change arg-s from _GET and $_GET if they are set -->

    <!-- ADDED DURING CURRENCY UPGRADE -->
    <? if (isset($_GET['currency'])): ?>
    <input type="hidden" name="currency" value="<? echo($_GET['currency']) ?>"></input>
    <? endif; ?>
    <!-- END ADDED -->


    <div class="box blue big-box left">
        <div class="inner clearfix">

            <div class="title"><?= lang('search.search_hotels') ?></div>

            <div class="form-vertical top-13">
                <label><?= lang('search.destination_or_hotel') ?></label>
                <input type="text" name="dest_hot" id="dest_hot" value="<?= $dest_hot ?>" />
            </div>

            <div class="form-vertical form-col top-10 clearfix">
                <div class="col">
                    <label><?= lang('search.check_in') ?></label>
                    <input type="text" name="check_in" id="check_in" value="<?= $check_in ?>" class="checkinout"/>
                </div>
                <div class="col">
                    <label><?= lang('search.check_out') ?></label>
                    <input type="text" name="check_out" id="check_out" value="<?= $check_out ?>" class="checkinout"/>
                </div>
            </div>

            <div class="form-vertical form-col top-10 clearfix fixcol">

                <div class="col clearfix">

                    <label><?= lang('search.adults') ?></label>

                    <select name="nr_adults" id="nr_adults" class="dropdownized">
                        <? for ($index = 1; $index <= $cnt; $index++): ?>
                        <option value = "<?= $index ?>" <? if ($selected == $index) echo $sel_text; ?>><?= $index ?></option>
                        <? endfor; ?>
                    </select>

                </div>

                <div class="col clearfix">

                    <label><?= lang('search.children') ?></label>

                    <select name="nr_childrens" id="nr_childrens" class="dropdownized">
                        <? for ($index = 0; $index <= $cnt_CH; $index++): ?>
                        <option value = "<?= $index ?>" <? if ($selected_CH == $index) echo $sel_text; ?>><?= $index ?></option>
                        <? endfor; ?>
                    </select>

                </div>

                <div class="col clearfix ages" <? if (isset($_GET['nr_childrens']) && $_GET['nr_childrens'] != 0) echo 'style="display:block"'; ?>>

                     <label><?= lang('search.ages') ?></label>

                    <div class="left mr10 age-1"><input type="text" name="ages[]" class="positive-integer" value="<? if (isset($_GET['ages'][0])) echo $_GET['ages'][0]; ?>" /></div>  
                    <div class="left mr10 age-2"><input type="text" name="ages[]" class="positive-integer" value="<? if (isset($_GET['ages'][1])) echo $_GET['ages'][1]; ?>" /></div>  
                    <div class="left mr10 age-3"><input type="text" name="ages[]" class="positive-integer" value="<? if (isset($_GET['ages'][2])) echo $_GET['ages'][2]; ?>" /></div>  
                    <div class="left mr10 age-4"><input type="text" name="ages[]" class="positive-integer" value="<? if (isset($_GET['ages'][3])) echo $_GET['ages'][3]; ?>" /></div>  
                    <div class="left mr10 age-5"><input type="text" name="ages[]" class="positive-integer" value="<? if (isset($_GET['ages'][4])) echo $_GET['ages'][4]; ?>" /></div>   

                </div>
            </div>
            
            <div class="form-vertical form-col top-10 fixcol clearfix">
                <div class="specific">
                    <input type="checkbox" id="non_specific_dates" name="preview" value="1" <? if (isset($_GET['preview'])) echo 'checked="checked"'; ?>/> 
                           <label for="preview"><?= lang('search.my_dates') ?></label>
                </div>
            </div>

            <div class="clearfix top-20">

                <? $method = $this->router->fetch_method(); ?>

                <? if ($method == "index"): ?>
                <div class="form-actions top-10"><button class="btn btn-primary"><?= lang('search.search_caption') ?></button></div>
                <? endif; ?>

                <? if ($method == "search" || $method == "popular" || $method == "accommodation" || $method == "details_preview"): ?>
                <div class="form-actions top-9"><button class="btn btn-primary"><?= lang('search.search_caption') ?></button></div>
                <? endif; ?>

            </div>
        </div>
    </div>

</form>
<?
//    $this->firephp->log($_GET);
?>
<script type="text/javascript">

    var nr_children = 0;
<?php if (!isset($_GET['ages'][0])): ?>
            doResetAges = true;
        <?php
    endif;

    if (isset($_GET['nr_childrens'])):
        ?>
            nr_children = '<?= $_GET['nr_childrens'] ?>';
        <?php
    endif;
?>

</script>